package com.jrx.anytxn.investor.service.impl;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.investor.constant.TransBizConstant;
import com.jrx.anytxn.investor.entity.AmLoanAccountInvestorInfo;
import com.jrx.anytxn.investor.entity.BtInvestorAccountingTransferList;
import com.jrx.anytxn.investor.service.IInvestorBtAccountingTransferListService;
import com.jrx.anytxn.number.exception.SegmentException;
import com.jrx.anytxn.number.service.ISegmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: anytxn-cf-transaction
 * @description:
 * @author: xiaoyu.jing
 * @date: 2020-05-25 21:17
 **/
@Service
public class InvestorBtAccountingTransferListServiceImpl implements IInvestorBtAccountingTransferListService {

    private static final Logger logger = LoggerFactory.getLogger(InvestorBtAccountingTransferListServiceImpl.class);


    @Autowired
    private ISegmentService segmentService;

    /**
     *
     * @param amLoanAccountInvestorInfo
     * @param bussinessDate
     * @return
     */
    @Override
    public BtInvestorAccountingTransferList build(AmLoanAccountInvestorInfo amLoanAccountInvestorInfo, Date bussinessDate) throws TxnBizException {
        BtInvestorAccountingTransferList transferList = new BtInvestorAccountingTransferList();
        BeanMapping.copy(amLoanAccountInvestorInfo,transferList);
        try {
            transferList.setId(segmentService.getId(TransBizConstant.BT_INVESTOR_ACCOUNTING_TRANSFER_LIST_ID));//id
        } catch (SegmentException e) {
            logger.error("主键生成错误", e);
            throw new TxnBizException(TxnRespCode.ERROR.getUserTips());
        }
        transferList.setBusinessDate(bussinessDate);
        transferList.setUpdateBy(TransBizConstant.SYS_OPRATE);
        transferList.setCreateTime(null);
        transferList.setUpdateTime(null);
        return transferList;
    }
}
